<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta name="viewport" content="width=device-width" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
 <title>附件导入</title>
 <link href="${ctxStatic}/css/iconfont.css" rel="stylesheet" />
 <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet" />
  <link href="${ctxStatic}/css/kpiuitanchu.css" rel="stylesheet" />
 <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
 <script src="${ctxStatic}/layui/layui.all.js"  type="text/javascript"></script>
 <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>

</head>
<body>
  <div class="layui-container">
   <div class="layui-upload">
    <div style="color: white">请选择年份：</div>
    <select id="year" lay-filter="year">
     <option value="">请选择</option>
     <option value="2025">2025年</option>
     <option value="2024">2024年</option>
     <option value="2023">2023年</option>
     <option value="2022">2022年</option>
     <option value="2021">2021年</option>
     <option value="2020">2020年</option>
     <option value="2019">2019年</option>
     <option value="2018">2018年</option>
     <option value="2017">2017年</option>
    </select>
    <input type="hidden" id="hidyear" value="${year}">
    <div style="color: white">请选择月份：</div>
    <select id="weekmouth" name="mouth">
     <option value="">请选择</option>
     <option value="1">1月</option>
     <option value="2">2月</option>
     <option value="3">3月</option>
     <option value="4">4月</option>
     <option value="5">5月</option>
     <option value="6">6月</option>
     <option value="7">7月</option>
     <option value="8">8月</option>
     <option value="9">9月</option>
     <option value="10">10月</option>
     <option value="11">11月</option>
     <option value="12">12月</option>
    </select>
    <input type="hidden" id="hidmonth" value="${month}">
    <input type="hidden" id="hidpath" value="">
    <button type="button" class="layui-btn layui-btn-normal" id="chooseFile">选择文件</button>
    <button type="button" class="layui-btn" id="upload">保存</button>
    <a target="_blank" href="${ctxStatic}/doc/gongzibiao.xlsx"> <img src="${ctxStatic}/images/help.png" style="width:20px;height:20px"></a>
   </div>
  </div>
<script>
layui.use('upload', function(){
    var upload = layui.upload;
    upload.render({
        elem: '#chooseFile'
        ,url: 'user_pay_upload' //接口
        ,method:'POST'
        ,accept: 'file'
        ,size: 102400
        ,before: function(obj){
            layer.load();
        }
        ,done: function(data){
            console.log(data);
            console.log(data.msg);
            layer.closeAll('loading');
            if(data.result>0){
                top.mylayui.msg("文件上传成功！", {icon: 1});
                $("#hidpath").val(data.msg);
            }
            else{
                top.mylayui.msg(data.msg, {icon: 0});
            }
        }
        ,complete:function(XHR){
        }
        ,error: function(){//请求异常回调
            layer.closeAll('loading');
            layer.msg('网络异常，请稍后重试！');
        }
    });

    $(document).on('click','#upload',function(){
        fileUpload();
    });
});

 $(function () {
     var passyear = $("#hidyear").val();
     var passmonth =$("#hidmonth").val();
     $("#year").val(passyear);
     $("#weekmouth").val(passmonth);
     // form.render('select');
 });
function fileUpload() {
    var year = $("#year").val();
    var month =  $("#weekmouth").val();
    var path = $("#hidpath").val();
    top.mylayui.confirm('确定要保存吗？',{icon: 0}, function(index,dd){
        top.mylayui.close(index);
        top.ShowZheZhao();
        $.ajax({
            type:"POST",
            url:"add_user_pay",
            data:{year:year,month:month,path:path},
            beforeSend:function(XHR){

            },
            success:function(data){
                top.mylayui.closeAll('loading');
                data=eval('('+data+')');
                if(data.result>0) {
                    CloseDialog(data.result, "数据保存成功");
                }else
                {
                    CloseDialog(data.result,data.msg);
                }
            },
            complete:function(XHR){

                top.ShowZheZhao();
                // top.mylayui.closeAll('loading');
            },
            error:function(){

            }
        });
    })
}


function checkData() {
   var year = $("#year").val();
   var month =  $("#weekmouth").val();
    if(attfileid =="") return "附件未上传成功！请稍后重试";
    if(year == "") return "请选择年份！";
    if(month == "") return "请选择月份！";
    return "ok";
}

function CloseDialog(result,msg){
    top.frames["iframe"].vUserPay.addresult(result,msg);
}
</script>
</body>
</html>